package com.urea.web.controller.urea;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.urea.common.annotation.Log;
import com.urea.common.core.controller.BaseController;
import com.urea.common.core.domain.AjaxResult;
import com.urea.common.enums.BusinessType;
import com.urea.system.domain.UserWxBinding;
import com.urea.system.service.IUserWxBindingService;
import com.urea.common.utils.poi.ExcelUtil;
import com.urea.common.core.page.TableDataInfo;

/**
 * 用户和微信绑定关系Controller
 * 
 * @author liuzd
 * @date 2023-08-01
 */
@RestController
@RequestMapping("/wx/binding")
public class UserWxBindingController extends BaseController
{
    @Autowired
    private IUserWxBindingService userWxBindingService;

    /**
     * 查询用户和微信绑定关系列表
     */
    @PreAuthorize("@ss.hasPermi('wx:binding:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserWxBinding userWxBinding)
    {
        startPage();
        List<UserWxBinding> list = userWxBindingService.selectUserWxBindingList(userWxBinding);
        return getDataTable(list);
    }

    /**
     * 导出用户和微信绑定关系列表
     */
    @PreAuthorize("@ss.hasPermi('wx:binding:export')")
    @Log(title = "用户和微信绑定关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserWxBinding userWxBinding)
    {
        List<UserWxBinding> list = userWxBindingService.selectUserWxBindingList(userWxBinding);
        ExcelUtil<UserWxBinding> util = new ExcelUtil<UserWxBinding>(UserWxBinding.class);
        util.exportExcel(response, list, "用户和微信绑定关系数据");
    }

    /**
     * 获取用户和微信绑定关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('wx:binding:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userWxBindingService.selectUserWxBindingById(id));
    }

    /**
     * 新增用户和微信绑定关系
     */
    @PreAuthorize("@ss.hasPermi('wx:binding:add')")
    @Log(title = "用户和微信绑定关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserWxBinding userWxBinding)
    {
        return toAjax(userWxBindingService.insertUserWxBinding(userWxBinding));
    }

    /**
     * 修改用户和微信绑定关系
     */
    @PreAuthorize("@ss.hasPermi('wx:binding:edit')")
    @Log(title = "用户和微信绑定关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserWxBinding userWxBinding)
    {
        return toAjax(userWxBindingService.updateUserWxBinding(userWxBinding));
    }

    /**
     * 删除用户和微信绑定关系
     */
    @PreAuthorize("@ss.hasPermi('wx:binding:remove')")
    @Log(title = "用户和微信绑定关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userWxBindingService.deleteUserWxBindingByIds(ids));
    }
}
